<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{width:20px;height:20px;background: red;position: absolute;border-radius: 50%;left:0;top:0;display:none;}
    </style>
</head>
<body style="height:2000px;">
    <div class="box"></div>
</body>
<script>
    var box = document.querySelector(".box");

    document.onmouseenter = function(){
        box.style.display = "block";
    }
    document.onmouseleave = function(){
        box.style.display = "none";
    }

    document.onmousemove = function(eve){
        var e = eve || window.event;

        // 将鼠标坐标设置给元素
        box.style.left = e.pageX + "px";
        box.style.top = e.pageY + "px";
    }
</script>
</html>